*** Settings ***
Documentation    TC03-Data Cleaning AIR Project By Port
Resource    ../../Keywords/Common_Head.robot
Resource    ../../Keywords/Common/Common_kw.robot
Force Tags    P1
Metadata    Author    Joe
Metadata    ID    14320
Library    XML

*** Test Cases ***
TC03-Data Cleaning AIR Project By Port
    Step 1 User Goes To Basic Data Management Tender List
    Step 2 User Goes To Pricing Collaboration Pricing Project
    Step 3 Input Following Attributes
    Step 4 User Select The Row Which Project Name Is
    Step 5 User Clicks Data Cleaning Button
    Step 6 User Clicks Upload Button
    Step 7 User Clicks Add File Button And Select The File
    Step 8 User Select Port Routing
    Step 9 User Clicks Start Button
    Step 10 User Clicks Download Button
    Step 11 Check The Values Of Download File With The Original
    Step 12 Modify The Download File And User Clicks Upload Button
    Step 13 User Click Start Button
    Step 14 User Click Download Button
    Step 15 User Clicks Close Button
    Step 16 User Clicks Yes When Asking Are You Sure To Close This
    Step 17 In Pricing Project Page User Selects TenderID Contains
    Step 18 Select This Project Click On Delete Project Button
    Step 19 User Goes To Basic Data Management Tender List2



*** Keywords ***
Step ${step} User Goes To Basic Data Management Tender List
    #************************Step 1******************************
    #  Do:
    #      User goes to Basic Data Management Tender List
    #      Click Create button
    #      Input with following attributes
    #      Tender ID some numbers such as 202408151435001 you can
    #     input with current datetime and some random number to
    #     avoid duplicate validation
    #      Tender Title some value such as Regression Test by
    #     Wendy001
    #      Customer 815 Miele
    #      Mode select all
    #      Level Global
    #      Click on Save button
    #  Expected:
    #      Created successfully with the message Tender has been
    #     added
    #************************************************************
    Empty Directory    ~/Downloads
    ${G_TENDERID}    Generate Tender ID
    Set Suite Variable     ${G_TENDERID}
    Login Space
    Create Tender    ${G_TENDERID}    Regress    815    true    true    true


Step ${step} User Goes To Pricing Collaboration Pricing Project
    #************************Step 2******************************
    #  Do:
    #      User goes to Pricing Collaboration Pricing Project
    #      User clicks Create Project button
    #  Expected:
    #      A New Project dialog should be opened successfully
    #************************************************************
    Log    NEXT STEP
Step ${step} Input Following Attributes
    #************************Step 3******************************
    #  Do:
    #      Input following attributes
    #      Tender ID 202408151435001 Regression Test by Wendy001
    #      Mode Air
    #      Deadline to TM current date 10 day
    #      Rate Validity From current date
    #      Rate Validity To current date 100 day
    #      Deputies NATZHANG
    #      Description for regression
    #      Click on Save button
    #  Expected:
    #      A new project is created successfully
    #************************************************************
    # Fill Text    ${Project_create_TenderID}    ${G_TENDERID}
    # Wait For Elements State    ${Project_create_TenderIdDropDown}    visible    60
    # Sleep    3
    # #3.User chooses the "R2018(Regress)" from the dropdown list.  
    # Click    ${Project_create_TenderIdDropDown}
    # Select Options By   ${Project_create_Mode}    label    AIR
    ${CurDate}    Get Current Date    result_format=%d/%m/%Y
    Set Test Variable    ${CurDate}    ${CurDate}
    # ${FutureDate}    Get Current Date    UTC    +10days    result_format=%d/%m/%Y
    # ${FutureDate+100}    Get Current Date    UTC    +100days    result_format=%d/%m/%Y
    # Fill Text    ${Project_create_DeadlinetoTMDate}    ${FutureDate} 
    # Fill Text    ${Project_create_RateValidityFrom}    ${CurDate}
    # Fill Text    ${Project_create_RateValidityTo}   ${FutureDate+100}
    # CLICK    //div[@id="deputies"]//button
    # fill text    //input[@id="000"]    NATZHANG
    # click    //div[@class="view-container"]//button[@name="locatorSearchButton"]
    # click    //td[.='NATZHANG']
    # click    //button[contains(text(),'Select')]
    # fill text    //textarea[@id="description"]    for regression
    # Click    ${Project_create_SaveButton}
    # Wait Until Search Finished
    ${ValidFrom}    Get Current Date    result_format=%d/%m/%Y
    Set Test Variable    ${ValidFrom}    ${ValidFrom}
    ${DeadLine}    Get Current Date    UTC    +10days    result_format=%d/%m/%Y
    ${ValidTo}    Get Current Date    UTC    +100days    result_format=%d/%m/%Y
    ${PROJECT}    Copy Dictionary    ${PROJECT_PARAM}
    Set To Dictionary    ${PROJECT}    
    ...    TENDER_ID=${G_TENDERID}    TENDER_TITLE=Regress    CUSTOEMR_NAME=Miele    CUSTOMER_LEVEL=Global
    ...   MODE=AIR    DEADLINE_TM_DATE=${DeadLine}    VALID_FROM=${ValidFrom}    VALID_TO=${ValidTo}    DEPUTY=NATZHANG
    Set Test Variable    ${PROJECT}    ${PROJECT}
    Create Project    ${PROJECT}
    Sleep    2
Step ${step} User Select The Row Which Project Name Is
    #************************Step 4******************************
    #  Do:
    #      User select the row which project name is
    #     202408151435001 AIR Regression Test by Wendy001
    #  Expected:
    #      The row is selected and the button of data cleaning is
    #     enabled
    #************************************************************
    click    //td[contains(text(),'${G_TENDERID}')]
    Wait For Elements State    ${Project_toolbar_DataCleaningButton}    enabled    20

Step ${step} User Clicks Data Cleaning Button
    #************************Step 5******************************
    #  Do:
    #      User clicks data cleaning button
    #  Expected:
    #      A dialogue named 202408151435001 AIR Regression Test by
    #     Wendy001 shows successfully
    #************************************************************
    click    ${Project_toolbar_DataCleaningButton}
    Wait For Elements State    //h4[contains(text(),'${G_TENDERID}')]    visible    20

Step ${step} User Clicks Upload Button
    #************************Step 6******************************
    #  Do:
    #      User clicks upload button
    #  Expected:
    #      A dialogue name Upload Template shows successfully
    #************************************************************
    Click    ${Data_toolbar_UploadButton}
    Wait For Elements State    ${Data_Upload_AddFile}    enabled    60

Step ${step} User Clicks Add File Button And Select The File
    #************************Step 7******************************
    #  Do:
    #      User clicks add file button and select the file
    #     AirTemplate Port All xlsx form local
    #  Expected:
    #      A table shows below upload button It contains document
    #     name and date time Document name is AirTemplate Location
    #     All xlsx date time is you uploaded time like 03 10 2018
    #     17 05
    #************************************************************
    ${Data_Upload_AddFile1}    Set Variable    xpath=//input[@name='file']
    Upload File By Selector    ${Data_Upload_AddFile1}    ${CURDIR}${/}TestData${/}AirTemplate-Port-All_updated for Air case03.xlsx
    Wait For Elements State    xpath=//label[.='Document Name']    visible    30 
    Wait For Elements State    //label[.='AirTemplate-Port-All_updated for Air case03.xlsx']    visible    20
    Wait For Elements State    //label[contains(text(),'${CurDate}')]    visible    20 
Step ${step} User Select Port Routing
    #************************Step 8******************************
    #  Do:
    #      User select port routing
    #      Select all of them
    #      User select map columns like that
    #      Origin Country country from F
    #      Destination Country country to I
    #      Origin Port Customer Origin Airport P
    #      Destination Port Customer Destination Airport Q
    #      Origin State state from G
    #      Destination State state to J
    #      Schenker Service Level Schenker Service Level C
    #      Customer Service Level TSP Transport Service Provider B
    #      MD LD MD LD K
    #      Customer Lane ID Lane ID code D
    #      Origin Type Origin Type L
    #      Destination Type Des Type M
    #      Origin Postal Code Origin Postal Code N
    #      Destination Postal Code Destination Postal Code O
    #      Customer Origin Place City From E
    #      Customer Destination Place City To H
    #      Number of Shipments Number of Shipments R
    #      Volume cbm Volume cbm S
    #      Actual weight in kg Actual weight in kg T
    #      Chargeable weight in kg Chargeable weight in kg U
    #      Commodity Description Commodity Description V
    #      Commodity Remarks Commodity Remarks W
    #      DGR Class DGR Class X
    #      DGR UN No DGR UN No Y
    #      DGR PAX CAO DGR PAX CAO Z
    #  Expected:
    #      They both should be select successfully
    #************************************************************
    click    ${Select_By_Port}
    Select Options By   ${Origin_Country}    label    ${SPACE}${SPACE}country from - F    Country from - F
    Select Options By   ${Destination_Country}     label    ${SPACE}${SPACE}country to - I        Country to - I
    Select Options By   ${Origin_Port}    label    Customer Origin Airport - P
    Select Options By   ${Destination_Port}    label    Customer Destination Airport - Q
    Select Options By   ${Origin_State}      label    State From - G    State From - G
    Select Options By   ${FCL_Select_Destination_State}   label    State To - J
    Select Options By   ${DB_Schenker_Service_Level}    label    Schenker Service Level - C
    Select Options By   ${Customer_Service_Level}    label    TSP - Transport Service Provider - B
    Select Options By   ${MD/LD}   label    MD/LD - K
    Select Options By   ${Air_Customer_Lane_ID}    label    Lane ID code - D
    Select Options By   ${Air_Origin_Type}     label   Origin Type - L
    Select Options By   ${Air_Destination_Type}    label    Des Type - M
    Select Options By   ${Air_Origin_Postal_Code}     label    Origin Postal Code - N
    Select Options By   ${Air_Destination_Postal_Code}  label    Destination Postal Code - O
    Select Options By   ${Customer_Origin_Place}   label       ${SPACE}city from - E
    Select Options By   ${AirCustomer_Destination_Place}    label      ${SPACE}${SPACE}city to - H
    Select Options By   ${Number_of_Shipments}    label    Number of Shippments - R
    Select Options By   ${Volume_cbm}   label    Volume(cbm) - S
    Select Options By   ${Actual_Weight_in_Kg}    label    Actual weight in kg - T
    Select Options By   ${Chargeable_Weight_in_Kg}     label    Chargeable weight in kg - U
    Select Options By   ${Air_Commodity_Desc}   label    Commodity Description - V
    Select Options By   ${Commodity_Remarks}     label    Commodity Remarks - W
    Select Options By   ${DGR_Class}   label    DGR Class - X
    Select Options By   ${DGR_UN_No}   label    DGR UN No. - Y
    Select Options By   ${DGR_PAX/CAO}    label    DGR PAX/CAO. - Z
    click    ${AIR_CheckBox__OriginState} 
    click    ${AIR_CheckBox__DestinationState}
    click    ${AIR_CheckBox_CustomerServiceLevel}
    click    ${FCL/AIR_CheckBox_CustomerLaneID}
    click    ${FCL/AIR_CheckBox_OriginType}
    click    ${FCL/AIR_CheckBox_DestType}
    click    ${FCL/AIR_CheckBox_OriginPostalCode}
    click    ${FCL/AIR_CheckBox_DestiPostalCode} 
    click    ${AIR_CheckBox_CustomerOrginPlace}
    click    ${AIR_CheckBox_CustomerDestinationPlace}
    click    ${AIR_CheckBox_NoOfShipments}
    click    ${AIR_CheckBox_VolumeCBM} 
    click    ${AIR_CheckBox_ActWghtInKg}
    click    ${AIR_CheckBox_ChrgWghtInKg}
    click    ${AIR_CheckBox_DGRClass}
    click    ${AIR_CheckBox_DGRUNNo}
    click    ${AIR_CheckBox_DGRPAX/CAO}
    click    ${AIR_CheckBox_CommdRemarks}
    click    ${FCL/AIR_CheckBox_CommDesc}


Step ${step} User Clicks Start Button
    #************************Step 9******************************
    #  Do:
    #      User clicks start button
    #  Expected:
    #      In the tab of step3 validation download upload and set
    #     pass buttons appears The summary shows successful
    #************************************************************
    click    ${Data_toolbar_StartButton}
    Wait For Elements State    ${Data_toolbar_DownloadButton}    visible    30 
    Wait For Elements State   ${Data_toolbar_UploadAfterStartButton}    visible    30 
    Wait For Elements State    ${Data_toolbar_SetPassButton}     visible    30 

Step ${step} User Clicks Download Button
    #************************Step 10******************************
    #  Do:
    #      User clicks download button
    #  Expected:
    #      File download successfully and the file named
    #     AIR_data_cleaning_template xlsx
    #************************************************************
    ${file_path}    Get Download ZIP File Name    ${G_TENDERID}    .zip
    Should Contain    ${file_path}   ${G_TENDERID}-AIR-Regress
    Set Test Variable    ${file_path}    ${file_path}
Step ${step} Check The Values Of Download File With The Original
    #************************Step 11******************************
    #  Do:
    #      Check the values of download file with the original
    #     file AirTemplate Port All xlsx
    #  Expected:
    #      Compare the two files the value of the same column
    #     should be equal
    #************************************************************
    ${DOWNLOAD_PATH}     Normalize Path    ${DOWNLOAD_PATH}
    Extract Zip File    ${file_path}    ${DOWNLOAD_PATH}
    ${FILES}    List Files In Directory   ${DOWNLOAD_PATH}   *.xlsx
    ${excelFile}     Set Variable    ${DOWNLOAD_PATH}${/}${FILES}[0]
    Set Test Variable    ${excelFile}    ${excelFile}
    Wait Until Keyword Succeeds    50    1    Open Excel Document    ${excelFile}    AIR
     ${Origin Country}    Read Excel Cell    2    7
     ${Destination Country}    Read Excel Cell    3    12
     ${Origin Airport}    Read Excel Cell    2    19
     ${DB Schenker Service Level}    Read Excel Cell    3    16
     ${Customer Service Level}    Read Excel Cell    2    17
     ${MD}    Read Excel Cell    2    26
     ${Customer Lane ID}    Read Excel Cell    3    2
     ${Origin type}    Read Excel Cell    2    18
     ${Destination type}    Read Excel Cell    3    23
     ${Origin Postal Code}    Read Excel Cell    3    9
     ${Destination Postal Code}    Read Excel Cell    3    15
     ${Origin City}    Read Excel Cell    2    7
     ${Destination City}    Read Excel Cell    2    13
     ${Number of Shipments}    Read Excel Cell    2    27
     ${Volume(cbm)}    Read Excel Cell    2    30
     ${Actual weight in kg}    Read Excel Cell    2    28
     ${Chargeable weight in kg}    Read Excel Cell    2    29
     ${Commodity Description}    Read Excel Cell    2    31
     ${Commodity Remarks}    Read Excel Cell    2    32
     ${DGR Class}    Read Excel Cell    2    33
     ${DGR UN No.}    Read Excel Cell    2    34
     ${DGR PAX/CAO}    Read Excel Cell    2    35
     Close All Excel Documents
     Open Excel Document    ${CURDIR}${/}TestData${/}AirTemplate-Port-All_updated for Air case03.xlsx    AIR
     ${Country from}    Read Excel Cell    2    5
     ${Country to}    Read Excel Cell    3    9
     ${Customer origin airport}    Read Excel Cell    2    16
     ${Schenker Service Level}    Read Excel Cell    3    3
     ${Transport Service Provider}    Read Excel Cell    2    2
     ${MD2}    Read Excel Cell    2    11
     ${Lane ID code}    Read Excel Cell    3    4
     ${Origin type2}    Read Excel Cell    2    12
     ${Destination type2}    Read Excel Cell    3    13
     ${Origin Postal Code2}    Read Excel Cell    3    14
     ${Destination Postal Code2}    Read Excel Cell    3    15
     ${city from}    Read Excel Cell    2    5
     ${city to}    Read Excel Cell    2    8
     ${Number of Shippments2}    Read Excel Cell    2    18
     ${Volume (cbm)2}    Read Excel Cell    2    19
     ${Actual weight in kg2}    Read Excel Cell    2    20
     ${Chargeable weight in kg2}    Read Excel Cell    2    21
     ${Commodity Description2}    Read Excel Cell    2    22
     ${Commodity Remarks2}    Read Excel Cell    2    23
     ${DGR Class2}    Read Excel Cell    2    24
     ${DGR UN No.2}    Read Excel Cell    2    25
     ${DGR PAX/CAO2}    Read Excel Cell    2    26
    Close All Excel Documents
    Should Be Equal    ${Origin Country}    ${Country from}
    Should Be Equal    ${Destination Country}     ${Country to}
    Should Be Equal    ${Origin Airport}    ${Customer origin airport}
    Should Be Equal    ${DB Schenker Service Level}     ${Schenker Service Level}
    Should Be Equal    ${Customer Service Level}     ${Transport Service Provider} 
    Should Be Equal    ${MD}     ${MD2}
    Should Be Equal As Integers    ${Customer Lane ID}    ${Lane ID code}
    Should Be Equal    ${Origin type}     ${Origin type2}
    Should Be Equal    ${Destination type}     ${Destination type2} 
    Should Be Equal    ${Origin Postal Code}     ${Origin Postal Code2}
    Should Be Equal    ${Destination Postal Code}    ${Destination Postal Code2}
    Should Be Equal    ${Origin City}     ${city from}
    Should Be Equal    ${Destination City}     ${city to}
    Should Be Equal    ${Number of Shipments}     ${Number of Shippments2}
    Should Be Equal    ${Volume(cbm)}     ${Volume (cbm)2}
    Should Be Equal    ${Actual weight in kg}     ${Actual weight in kg2}
    Should Be Equal    ${Chargeable weight in kg}    ${Chargeable weight in kg2}
    Should Be Equal    ${Commodity Description}     ${Commodity Description2}
    Should Be Equal    ${Commodity Remarks}     ${Commodity Remarks2}
    Should Be Equal    ${DGR Class}     ${DGR Class2}
    Should Be Equal    ${DGR UN No.}     ${DGR UN No.2}
    Should Be Equal    ${DGR PAX/CAO}     ${DGR PAX/CAO2}


Step ${step} Modify The Download File And User Clicks Upload Button
    #************************Step 12******************************
    #  Do:
    #      Modify the download file and user clicks upload button
    #  Expected:
    #      The start button appears
    #************************************************************
    Open Excel Document    ${excelFile}    AIR
    Write Excel Cell    2    27    12    AIR
    Save Excel Document   ${excelFile}
    Close All Excel Documents
    Data Upload Template After Modified    ${G_TENDERID}-AIR-Regress   ${excelFile}
    Wait For Elements State   ${Data_toolbar_StartButton}     enabled
    

Step ${step} User Click Start Button
    #************************Step 13******************************
    #  Do:
    #      User click start button
    #  Expected:
    #      Wait a few seconds there is a successful prompt below
    #     the buttons like that Summary Successful
    #      Please close this page and go to Generate Internal
    #     Pricing Template
    #************************************************************
    Click    ${Data_toolbar_StartButton}
    Remove All Files

Step ${step} User Click Download Button
    #************************Step 14******************************
    #  Do:
    #      User click download button
    #  Expected:
    #      File download successfully Check the modified area the
    #     values are equal with the modified values
    #************************************************************
    ${zipFile}    Get Download ZIP File Name    ${G_TENDERID}    .zip
    Check Modified Excel File    ${zipFile}    2    27    AIR    12

Step ${step} User Clicks Close Button
    #************************Step 15******************************
    #  Do:
    #      User clicks close button
    #  Expected:
    #      A warning dialogue display and ask you Are you sure to
    #     close this page
    #************************************************************
    click    ${Data_toolbar_CloseButton} 
    

Step ${step} User Clicks Yes When Asking Are You Sure To Close This
    #************************Step 16******************************
    #  Do:
    #      User clicks yes when asking Are you sure to close this
    #     page
    #  Expected:
    #      The dialogue disappears
    #************************************************************
    click    //button//span[.='Yes']

Step ${step} In Pricing Project Page User Selects TenderID Contains
    #************************Step 17******************************
    #  Do:
    #      In Pricing Project page User selects TenderID Contains
    #     20240815
    #  Expected:
    #      The project 20240815 AIR Regression could be found
    #************************************************************
    click    //td[contains(text(),'${G_TENDERID}')]

Step ${step} Select This Project Click On Delete Project Button
    #************************Step 18******************************
    #  Do:
    #      Select this project click on Delete Project button
    #      Click Yes of the pop up confirm window
    #  Expected:
    #      System displays Project has been deleted
    #************************************************************
    Log    teardown

Step ${step} User Goes To Basic Data Management Tender List2
    #************************Step 19******************************
    #  Do:
    #      User goes to Basic Data Management Tender List
    #      Search out the tender created in step1
    #      Click on Delete button
    #      Click on Yes button in the popup dialog
    #  Expected:
    #      System displays Tender has been deleted
    #************************************************************
    Log    teardown
